#ifndef CARDITEM_H
#define CARDITEM_H

#include <QGraphicsObject>
#include <QPainter>
#include <QPropertyAnimation>
#include "card.h"

// 显示在界面中的卡牌图元
class CardItem: public QGraphicsObject
{
    Q_OBJECT
    Q_PROPERTY(int angle READ angle WRITE setAngle) // 必须将其声明为Q属性
private:
    bool isSelected = false;

    QSizeF m_size; //宽高

    int m_angle=0; //角度
    bool isFlipped=false; //是否已经翻转
    QPropertyAnimation* flip_animation; //翻转用到的动画

    Card m_card;
public:
    // 是否绘制灰色遮罩
    bool drawGrayMask=false;

    explicit CardItem(Card &&card, const QSizeF& size, QGraphicsItem *parent = 0);

    QRectF boundingRect() const override;

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;

    void changeSelectStatus(); //选中和未选中来回切换

    bool getSelectStatus(){ return isSelected; }

    void flip(); //翻转

    int angle() const { return m_angle; }
    void setAngle(int angle){
        m_angle = angle;
        update();
    }
    Card getCard() const { return m_card; };
};

#endif // CARDITEM_H
